package com.youyi.yyviewsdklibrary.Dialog.impl;

import android.content.Context;
import android.graphics.Rect;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.FrameLayout;
import com.youyi.yyviewsdklibrary.Dialog.animator.PopupAnimator;
import com.youyi.yyviewsdklibrary.Dialog.animator.TranslateAnimator;
import com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView;
import com.youyi.yyviewsdklibrary.Dialog.enums.PopupAnimation;
import com.youyi.yyviewsdklibrary.Dialog.enums.PopupPosition;
import com.youyi.yyviewsdklibrary.Dialog.interfaces.OnClickOutsideListener;
import com.youyi.yyviewsdklibrary.Dialog.util.XPopupUtils;
import com.youyi.yyviewsdklibrary.Dialog.widget.PartShadowContainer;
import com.lkx.liandianqinew.R;

public abstract class PartShadowPopupView extends BasePopupView {
    protected PartShadowContainer attachPopupContainer = ((PartShadowContainer) findViewById(R.id.attachPopupContainer));
    public boolean isShowUp;

    public PartShadowPopupView(Context context) {
        super(context);
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public final int getInnerLayoutId() {
        return R.layout._xpopup_partshadow_popup_view;
    }

    /* access modifiers changed from: protected */
    public void addInnerContent() {
        this.attachPopupContainer.addView(LayoutInflater.from(getContext()).inflate(getImplLayoutId(), (ViewGroup) this.attachPopupContainer, false));
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public void initPopupContent() {
        if (this.attachPopupContainer.getChildCount() == 0) {
            addInnerContent();
        }
        if (this.popupInfo.hasShadowBg.booleanValue()) {
            this.shadowBgAnimator.targetView = getPopupContentView();
        }
        getPopupContentView().setTranslationY((float) this.popupInfo.offsetY);
        getPopupImplView().setTranslationX((float) this.popupInfo.offsetX);
        getPopupImplView().setTranslationY(0.0f);
        getPopupImplView().setVisibility(View.INVISIBLE);
        XPopupUtils.applyPopupSize((ViewGroup) getPopupContentView(), getMaxWidth(), getMaxHeight(), getPopupWidth(), getPopupHeight(), new Runnable() {
            /* class com.youyi.yyviewsdklibrary.Dialog.impl.PartShadowPopupView.AnonymousClass1 */

            public void run() {
                PartShadowPopupView.this.doAttach();
            }
        });
    }

    /* access modifiers changed from: private */
    /* access modifiers changed from: public */
    private void initAndStartAnimation() {
        initAnimator();
        doShowAnimation();
        doAfterShow();
    }

    public void doAttach() {
        if (this.popupInfo.atView != null) {
            MarginLayoutParams marginLayoutParams = (MarginLayoutParams) getPopupContentView().getLayoutParams();
            marginLayoutParams.width = getMeasuredWidth();
            Rect atViewRect = this.popupInfo.getAtViewRect();
            atViewRect.left -= getActivityContentLeft();
            atViewRect.right -= getActivityContentLeft();
            if (!this.popupInfo.isCenterHorizontal || getPopupImplView() == null) {
                int i = atViewRect.left + this.popupInfo.offsetX;
                int measuredWidth = getActivityContentView().getMeasuredWidth();
                if (getPopupImplView().getMeasuredWidth() + i > measuredWidth) {
                    i -= (getPopupImplView().getMeasuredWidth() + i) - measuredWidth;
                }
                getPopupImplView().setTranslationX((float) i);
            } else {
                getPopupImplView().setTranslationX((float) (((atViewRect.left + atViewRect.right) / 2) - (getPopupImplView().getMeasuredWidth() / 2)));
            }
            int height = atViewRect.top + (atViewRect.height() / 2);
            View popupImplView = getPopupImplView();
            LayoutParams layoutParams = (LayoutParams) popupImplView.getLayoutParams();
            if ((height > getMeasuredHeight() / 2 || this.popupInfo.popupPosition == PopupPosition.Top) && this.popupInfo.popupPosition != PopupPosition.Bottom) {
                marginLayoutParams.height = atViewRect.top;
                this.isShowUp = true;
                layoutParams.gravity = 80;
                if (getMaxHeight() != 0) {
                    layoutParams.height = Math.min(popupImplView.getMeasuredHeight(), getMaxHeight());
                }
            } else {
                marginLayoutParams.height = getMeasuredHeight() - atViewRect.bottom;
                this.isShowUp = false;
                marginLayoutParams.topMargin = atViewRect.bottom;
                layoutParams.gravity = 48;
                if (getMaxHeight() != 0) {
                    layoutParams.height = Math.min(popupImplView.getMeasuredHeight(), getMaxHeight());
                }
            }
            getPopupContentView().setLayoutParams(marginLayoutParams);
            popupImplView.setLayoutParams(layoutParams);
            getPopupContentView().post(new Runnable() {
                /* class com.youyi.yyviewsdklibrary.Dialog.impl.PartShadowPopupView.AnonymousClass2 */

                public void run() {
                    PartShadowPopupView.this.initAndStartAnimation();
                    PartShadowPopupView.this.getPopupImplView().setVisibility(View.VISIBLE);
                }
            });
            this.attachPopupContainer.setOnLongClickListener(new OnLongClickListener() {
                /* class com.youyi.yyviewsdklibrary.Dialog.impl.PartShadowPopupView.AnonymousClass3 */

                public boolean onLongClick(View view) {
                    if (!PartShadowPopupView.this.popupInfo.isDismissOnTouchOutside.booleanValue()) {
                        return false;
                    }
                    PartShadowPopupView.this.dismiss();
                    return false;
                }
            });
            this.attachPopupContainer.setOnClickOutsideListener(new OnClickOutsideListener() {
                /* class com.youyi.yyviewsdklibrary.Dialog.impl.PartShadowPopupView.AnonymousClass4 */

                @Override // com.youyi.yyviewsdklibrary.Dialog.interfaces.OnClickOutsideListener
                public void onClickOutside() {
                    if (PartShadowPopupView.this.popupInfo.isDismissOnTouchOutside.booleanValue()) {
                        PartShadowPopupView.this.dismiss();
                    }
                }
            });
            return;
        }
        throw new IllegalArgumentException("atView must not be null for PartShadowPopupView！");
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public PopupAnimator getPopupAnimator() {
        return new TranslateAnimator(getPopupImplView(), getAnimationDuration(), this.isShowUp ? PopupAnimation.TranslateFromBottom : PopupAnimation.TranslateFromTop);
    }

    /* access modifiers changed from: protected */
    @Override // com.youyi.yyviewsdklibrary.Dialog.core.BasePopupView
    public int getMaxWidth() {
        return XPopupUtils.getAppWidth(getContext());
    }
}
